﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Applee.FractCommon;
using System.Reflection;
using System.IO;
using System.Windows.Forms;

namespace Applee.FractManager
{
    class FractFactory
    {
        public static IDrawable CreateFract(string strName)
        {
            //IDrawable drawable = null;
            //switch(strName)
            //{
            //    case "请选择...":
            //        break;
            //    case "Durer五边形":
            //        drawable = new DurerFract.DurerFract();
            //        break;
            //    default:
            //        throw new NotImplementedException();
            //}

            //return drawable;

            IDrawable drawable = null;

            try
            {
                FractConf instance = FractConf.Instance;
                string strClass = instance.GetClass(strName);

                string strPath = instance.GetPath(strName);
                strPath = Path.Combine(Application.StartupPath, strPath);

                if (File.Exists(strPath))
                {
                    Assembly asse = Assembly.LoadFile(strPath);
                    Type type = asse.GetType(strClass);
                    ConstructorInfo constructor = type.GetConstructor(new Type[0]);

                    drawable = (IDrawable)constructor.Invoke(new Object[0]);
                }

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return drawable;

        }
    }
}
